import Vue from 'vue'
import {domain , defaultLanguage} from '@/config.js'

function upload (url, filepath, key, data, fn){
	uni.showLoading({
		title: '正在上传...',
		icon: 'loading',
	});
	data.token = data.token || uni.getStorageSync('token');
	let domainUrl = uni.getStorageSync('available_domain') || domain
	uni.uploadFile({
	  url: domainUrl + url,
	  filePath: filepath,
	  name: key,
	  formData: data,
	  success: (uploadFileRes) => {
	    fn && fn(JSON.parse(uploadFileRes.data))
	  },
		complete: () => {
			 uni.hideLoading()
		}
	});
}
Vue.prototype.$upload = upload;

function copy(txt) {
	// #ifdef APP-PLUS
	uni.setClipboardData({
		data: txt.toString(),
		success: function() {
			let version=uni.getStorageSync('lang') || defaultLanguage;
			if(version == "en-us"){
				uni.showToast({
					icon: 'none',
					title: 'Copy successfully!'
				});	
			}else if(version == "zh-cn"){
				uni.showToast({
					icon: 'none',
					title: '复制成功!'
				});	
			}
		}
	});
	// #endif
	// #ifdef H5
	uni.showToast({
		icon: 'none',
		title: '当前环境暂不支持'
	});
	// #endif
}
Vue.prototype.$copy = copy;



